import { Component, OnInit } from '@angular/core';
import { Location } from '@angular/common';
import { Router, ActivatedRoute, Params } from '@angular/router';
import { Service } from '../server/server';
import { HeaderService } from 'app/core/services/header.service';
declare var $: any;
@Component({
	selector: 'app-product',
	templateUrl: './product.component.html'
})
export class ProductComponent implements OnInit {

	right: any = {
		"listAll":{}, //任务列表
		"AuditAll":{},
		"productList":{},
		"productAudit":{},
		"internalList":{},
		"internalAudit":{}
	};

	constructor(
		private Location: Location,
		private activatedRoute: ActivatedRoute,
		public router: Router,
		private server: Service,
		private headerService: HeaderService, 
		) { 
			this.right = $.extend(this.right, server.getRight());
		}

	taskType:any = '0';
	auditWidth:any = '';
	public isActive = this.server.isActive;
	ngOnInit() {
		this.activatedRoute.queryParams.subscribe((p: Params) => {
			this.taskType = String(p['taskType']);
		});
		this.server.eventEmit.subscribe((value: any) => {
			this.isActive = value;
			if(this.isActive){
                //展开
                $("#myTabContentProduct").css('width', this.auditWidth + 'px'); 
            }else{
				this.auditWidth = $("#myTabContentProduct").parent().width();
                //收缩，100%
                $("#myTabContentProduct").css('width','100%');
            }
		});

		this.activatedRoute.url.subscribe(r => {
            //权限
            if(this.taskType == '1'){
                //内文任务
				this.right['listAll'] = this.right['internalList'];
				this.right['AuditAll'] = this.right['internalAudit'];
            }else if(this.taskType == '0'){
                //产品任务
				this.right['listAll'] = this.right['productList'];
				this.right['AuditAll'] = this.right['productAudit'];
			}else if(this.taskType == '2'){
                //主题词标引任务
				this.right['listAll'] = this.right['themeTaskList'];
				this.right['AuditAll'] = this.right['themeTaskAudit'];
			}
        })
	}

	//跳转页面
	onPage(type:any){
		if(type =="list"){
			$('#myTabContentProduct').css('width','100%');
			this.router.navigate(['/product/list'],{queryParams:{ taskType:this.taskType }}); 
		}else if(type =="audit"){
			if(this.isActive && this.auditWidth == ''){
				this.auditWidth = $("#myTabContentProduct").parent().width();
			}
			$('#myTabContentProduct').css('width',this.auditWidth+'px');
			this.router.navigate(['/product/audit'],{queryParams:{ taskType:this.taskType }}); 
		}
		
	}

	//跳转页面
	onPageClick(type:any){
		this.taskType = type;
		this.router.navigate(['/product/list'],{queryParams:{ taskType:type }}); 
	  }

}
